import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import * as menuService from '../../../services/menus';
import * as common from '../../../utils/common';
import numeral from 'numeral';

const daoName = "MinOper";
const ButtonGroup = Button.Group;
const renderNumber = (num) => {
  let value = ''
  if (num) {
      value = numeral(num).format('0,0')
  }
  return value
};
const columns = [
    { title: '交易日期', width: 110, sorter: true, key: 'TRTD', caption: "TRTD", render: data => datetime.format(data.TRTD, "yyyy-MM-dd"), dispaly: true, filter: true },
    { title: '营业网点', width: 110, sorter: true, nowrap: true, caption: "OrganName", key: 'OrganName', dispaly: true, filter: true },
    { title: '科目', width: 100, sorter: true, dataIndex: 'ITNM', key: 'ITNM', dispaly: true, filter: true },
    { title: '收费名称', width: 215, sorter: true, nowrap: true, caption: "CHNM", key: 'CHNM', dispaly: true, filter: true },
    { title: '付款帐号', width: 215, sorter: true, dataIndex: 'ACNO', key: 'ACNO', dispaly: true, filter: true },
    { title: '付款户名', width: 260, sorter: true, nowrap: true, caption: "CUNM", key: 'CUNM', dispaly: true, filter: true },
    { title: '收费总额', width: 110, sorter: true, dataIndex: 'HDCH', key: 'HDCH', dispaly: true, filter: true },
    { title: '中间业务类型', width: 180, sorter: true, dataIndex: 'ITNM3', key: 'ITNM3', dispaly: true, filter: true },

    // { title: '客户经理1', width: 100, sorter: false, dataIndex: 'KHJL1', key: 'KHJL1', dispaly: true, filter: false },
    // { title: '金额1', width: 110, sorter: true, dataIndex: 'JE1', key: 'JE1', dispaly: true, filter: false },
    // { title: '客户经理2', width: 100, sorter: false, dataIndex: 'KHJL2', key: 'KHJL2', dispaly: true, filter: false },
    // { title: '金额2', width: 110, sorter: true, dataIndex: 'JE2', key: 'JE2', dispaly: true, filter: false },
    // { title: '客户经理3', width: 100, sorter: false, dataIndex: 'KHJL3', key: 'KHJL3', dispaly: true, filter: false },
    // { title: '金额3', width: 110, sorter: true, dataIndex: 'JE3', key: 'JE3', dispaly: true, filter: false },
    // { title: '客户经理4', width: 100, sorter: false, dataIndex: 'KHJL4', key: 'KHJL4', dispaly: true, filter: false },
    // { title: '金额4', width: 110, sorter: true, dataIndex: 'JE4', key: 'JE4', dispaly: true, filter: false },
    // { title: '客户经理5', width: 100, sorter: false, dataIndex: 'KHJL5', key: 'KHJL5', dispaly: true, filter: false },
    // { title: '金额5', width: 110, sorter: true, dataIndex: 'JE5', key: 'JE5', dispaly: true, filter: false },
    { title: '客户经理1', width: 180, sorter: false, dataIndex: 'YG1', key: 'YG1', dispaly: true, filter: false },
    { title: '分配比例1(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB1', render: data => common.formatNumber(data.ZB1/100), key: 'ZB1', dispaly: true, filter: false },
    { title: '客户经理2', width: 180, sorter: false, dataIndex: 'YG2', key: 'YG2', dispaly: true, filter: false },
    { title: '分配比例2(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB2', render: data => common.formatNumber(data.ZB2/100), key: 'ZB2', dispaly: true, filter: false },
    { title: '客户经理3', width: 180, sorter: false, dataIndex: 'YG3', key: 'YG3', dispaly: true, filter: false },
    { title: '分配比例3(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB3', render: data => common.formatNumber(data.ZB3/100), key: 'ZB3', dispaly: true, filter: false },
    { title: '客户经理4', width: 180, sorter: false, dataIndex: 'YG4', key: 'YG4', dispaly: true, filter: false },
    { title: '分配比例4(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB4', render: data => common.formatNumber(data.ZB4/100), key: 'ZB4', dispaly: true, filter: false },
    { title: '客户经理5', width: 180, sorter: false, dataIndex: 'YG5', key: 'YG5', dispaly: true, filter: false },
    { title: '分配比例5(%)', width: 100, sorter: false, className: "column-money", caption: 'ZB5', render: data => common.formatNumber(data.ZB5/100), key: 'ZB5', dispaly: true, filter: false },

  ];
const controls = [
    { name: 'TRTD', required: true, type: 'date', label: '交易日期',dataType: "date", min: 1, max: 50, grid: 12 / 24 },
    { name: 'OrganName', required: true, type: 'text', label: '营业网点', min: 1, max: 50, grid: 12 / 24 },
    { name: 'ITNM', required: true, type: 'text', label: '科目', min: 1, max: 50, grid: 12 / 24 },
    { name: 'CHNM', required: true, type: 'text', label: '收费名称',  grid: 12 / 24 },
    { name: "ACNO", required: true, type: 'text', label: '付款帐号', min: 1, max: 50, grid: 12 / 24 },
    { name: "CUNM", required: true, type: 'text', label: '付款户名',  grid: 12 / 24 },
    { name: 'HDCH', required: true, type: 'number', label: '收费总额', dataType: "number",min: 1, max: 50, grid: 12 / 24 },
    { name: 'ITNM3', required: true, type: 'text', label: '中间业务类型', min: 1, max: 50, grid: 12 / 24 },
];
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
/*对公存款 */
class MinOperForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataChange: false
    };
  }
  componentDidMount() {
    this.props.dispatch({
      type: `${daoName}/setKeyName`,
      payload: { keyName: "ID", permID: this.props.permID }
    });
    let sort = {
      field: 'TRTD',
      order: 'descend'
    }
    this.props.dispatch({
      type: `${daoName}/fetch`,
      payload: { daoName, page: 1, pageSize: 20,sorter:sort }
    });
    this.loadOptionData();
  }
  loadOptionData() {
    let options = []
    controls.map(c => {
      if (c.fetch) {
        let f = c.fetch;
        if (c.type === 'cascader-select') {
          f.isCascader = true;
        }
        if (c.type !== 'search') {
          options.push(f);
        }
      }
    })
    if (daoName && options.length > 0) {
      this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
    }
  }

  render() {
    let { showEdit, record, permID } = this.props;
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div>
          <div className={styles.create}>
          </div>
          <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID} />
        </div>
      </div>
    )
  }
}
function mapStateToProps(state) {
  const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
  return {
    showEdit,
    selectedRowKeys,
    keyName,
    record
  }
}
MinOperForm = connect(mapStateToProps)(MinOperForm)
export default MinOperForm;
let render = (props) => React.createElement(MinOperForm, props);
let f = new Factory()
f.set("MinOperForm", render)